package com.sfddata.musicpillow.user.mapper;

import com.sfddata.musicpillow.user.entity.CouldHaveReportDo;
import com.sfddata.musicpillow.user.entity.MonthReportInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author jiangyingou
* @description 针对表【month_report_info】的数据库操作Mapper
* @createDate 2023-06-16 15:46:32
* @Entity com.sfddata.musicpillow.user.entity.MonthReportInfo
*/
public interface MonthReportInfoMapper extends BaseMapper<MonthReportInfo> {

    @Select(
            "select sub.mon , count(*) count from\n" +
                    "(\n" +
                    "\tselect col_user_id,substring(col_date, 1, 7) mon \n" +
                    "\tfrom tb_sleep_record\n" +
                    "\twhere col_user_id = #{userId} \n" +
                    ") sub\n" +
                    "group by (sub.mon) having count >= 7 "

    )
    List<CouldHaveReportDo> selectMonthCouldHaveReport(@Param("userId") int userId);


    @Select(
            "select substring(start_day, 1, 7) mon from `month_report_info` where user_id = #{userId}"
    )
    List<String> selectMonthHaveReport(@Param("userId") int userId);
}




